import { createSSRApp } from 'vue'
import App from './App.vue'
import plugins from './plugins'
import router from './router'
import './styles/index.scss'
import { setupMixin } from './mixins'

// 导入并挂载全局的分享方法
import Share from './utils/share'

function getInvitationCodeFromUrl() : string | null {
	const params = new URLSearchParams(window.location.search);
	return params.get('pid');
}

const pid = getInvitationCodeFromUrl();
if (pid) {
	console.log(`邀请码: ${pid}`);
	// 处理邀请码...
	uni.setStorageSync('pid',pid)
} else {
	console.log('没有找到邀请码。');
}

export function createApp() {
	const app = createSSRApp(App)
	setupMixin(app)
	app.mixin(Share) // 使用mixin全局混入
	app.use(plugins)
	app.use(router)
	return {
		app
	}
}